from AlignedSent import AlignedSent

class AlignedSentCollection(object):
    # at the moment it's implemented as a list of AlignedSent class.
    # but can also be implemented as dictionary with the sentence # as key
    # self.alignedsents

    # sets of words in different languages
    # word_set1, word_set2

    def __init__(self):
        self.alignedsents = []
        self.word_set1 = dict()
        self.word_set2 = dict()
        self.word_set1_lang = ''
        self.word_set2_lang = ''

    def add_alignedsent(self, alignedsent):
        if self.alignedsents == []:
            self.word_set1_lang = alignedsent.lang1
            self.word_set2_lang = alignedsent.lang2
        self.alignedsents.append(alignedsent)
        for word in alignedsent.t1:
            if self.word_set1.has_key(word):
                self.word_set1[word] += 1
            else:
                self.word_set1[word] = 1
        for word in alignedsent.t2:
            if self.word_set2.has_key(word):
                self.word_set2[word] += 1
            else:
                self.word_set2[word] = 1

    def vocabulary(self):
        return (len(self.word_set1.keys()), len(self.word_set2.keys()))
    
    def remove_alignedsent(self, alignedsent):
        for word in alignedsent.t1:
            self.word_set1[word] -= 1
            if self.word_set1[word] == 0:
                del self.word_set1[word]
        for word in alignedsent.t2:
            self.word_set2[word] -= 1
            if self.word_set2[word] == 0:
                del self.word_set2[word]
        
                


        
